<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
        <title>登录页面</title>
		
		<!-- Favicon -->
        <link rel="shortcut icon" href="../function/assets/img/favicon.png">
	
		<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,400&display=swap">

		<!-- Bootstrap CSS -->
        <link rel="stylesheet" href="../function/assets/plugins/bootstrap/css/bootstrap.min.css">
		
		<!-- Fontawesome CSS -->
		<link rel="stylesheet" href="../function/assets/plugins/fontawesome/css/fontawesome.min.css">
		<link rel="stylesheet" href="../function/assets/plugins/fontawesome/css/all.min.css">
		<script src="../../js/sweetalert.min.js" type="text/javascript"></script>
		<script src="../../js/jquery-1.11.3.min.js"></script>
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="../function/assets/css/style.css">
    </head>
    <body>
	
		<!-- Main Wrapper -->
        <div class="main-wrapper login-body">
            <div class="login-wrapper">
            	<div class="container">
                	<div class="loginbox">
                    	<div class="login-left">
							<img class="img-fluid" src="../function/assets/img/logo-white.png" alt="Logo">
                        </div>
                        <div class="login-right">
							<div class="login-right-wrap">
								<h1>管理员登录</h1>
								<p class="account-subtitle">欢迎您访问学生信息管理系统</p>
								
								<!-- Form -->
<!--								<form action="../function/index.html">-->
								<form method="post">
									<div class="form-group">
										<input class="form-control" required="" id="username" name="username" type="text" placeholder="账号">
									</div>
									<div class="form-group">
										<input  class="form-control" type="password" required="" id="password" name="password" type="text" placeholder="密码">
									</div>
									<div class="checkbox">
										<label>
											<input type="checkbox" value="remember-me" id="checkbox" value="2"> 记住我
											<input type="hidden" name="checkbox" id="checkbox2" value="2">
											<input type="hidden" name="checkbox" id="checkbox1" value="2">
										</label>
									</div>
									<div class="form-group">
										<button class="btn btn-primary btn-block btn-login" type="button" id="login">登录</button>
									</div>
								</form>
								<!-- /Form -->
								
								<div class="text-center forgotpass"><a href="../function/forgot-password.html">找回密码</a></div>
<!--								<div class="login-or">-->
<!--									<span class="or-line"></span>-->
<!--									<span class="span-or">or</span>-->
<!--								</div>-->
								  
								<!-- Social Login -->
<!--								<div class="social-login">-->
<!--									<span>Login with</span>-->
<!--									<a href="#" class="facebook"><i class="fab fa-facebook-f"></i></a><a href="#" class="google"><i class="fab fa-google"></i></a>-->
<!--								</div>-->
								<!-- /Social Login -->
								
<!--								<div class="text-center dont-have">注册新账号 <a href="register.html">注册</a></div>-->
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!-- /Main Wrapper -->
		<script src="../function/assets/js/sweetalert.min.js"></script>
		
		<!-- jQuery -->
        <script src="../function/assets/js/jquery-3.5.1.min.js"></script>
		
		<!-- Bootstrap Core JS -->
        <script src="../function/assets/js/popper.min.js"></script>
        <script src="../function/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
		<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>


		<!-- Custom JS -->
		<script src="../function/assets/js/script.js"></script>

<!--		<script src="https://cdn.jsdelivr.net/npm/@bootcss/v3.bootcss.com@1.0.14/assets/js/ie10-viewport-bug-workaround.js"></script>-->

		<script type="text/javascript">


			$(function () {


				$('#login').click(function () {
					//获取username的cookie value
					if($("input[type='checkbox']").is(':checked')){
						//如果记住了密码
						$('#checkbox2').val('1'); //就将当前的checkbox的值设置为1
					}else{
						$('#checkbox2').val('2');
					}
					var username = $('#username').val();
					var password = $('#password').val();
					var checkboxs = $('#checkbox2').val();
					//判断当前的账号密码是否为空或者为空值
					if($.trim(username)==null || $.trim(username)==''){
						swal({
							title : "登陆操作提示",
							type : "error",
							text : "账号不能为空",
							confirmButtonText : "确定",
							closeOnConfirm : false
						});
						return false;
					}

					if($.trim(password)==null || $.trim(password)==''){
						swal({
							title : "登陆操作提示",
							type : "error",
							text : "密码不能为空",
							confirmButtonText : "确定",
							closeOnConfirm : false
						});
						return false;
					}
					$.ajax({
						url:'./user.do',
						dataType:'text',
						type:'POST',
						data:{
							username:$('#username').val(),
							password:$('#password').val(),
							checkbox:$('#checkbox2').val(),
							checkbox1:$('#checkbox1').val(), //是否对密码框的密码进行了更改
							action:'login'
						},
						success:function (data) {//如果返回数据为1，说明登陆失败
							if (data==1){
								swal({
									title : "登陆操作提示",
									type : "error",
									text : "登陆失败请仔细检查账号密码是否正确",
									confirmButtonText : "确定",
									closeOnConfirm : false
								});
							}else {
								window.location.href="../function/index.html"
							}

						}
					})


				})


				// //使用cookie记住账号和密码
				var username = $.cookie('adminusername');
				var password = $.cookie('adminpassword');


				$('#username').val(username);//展示被记住的用户名
				$('#password').val(password);//展示被记住的密码


				//判断当前是否对密码框的内容进行了修改
				$("input:password").bind("input propertychange",function(){

					$('#checkbox1').val('1'); //表示当前对密码框的值进行了修改，表示我修改过密码框的值

				});

			})
		</script>
<!--		<script src="../js/jquery-1.11.3.min.js"></script>-->

<!--	<script>-->
<!--		$(function () {-->
<!--			$('.btn-login').click(function () {-->
<!--				$.ajax({-->
<!--					type:'POST',-->
<!--					url:'./user.do',-->
<!--					data:{-->
<!--						username:$('#username').val(),-->
<!--						password:$('#password').val(),-->
<!--						action:'login'-->
<!--					},-->
<!--					dataType:'text',-->
<!--					success:function (data) {-->
<!--						if (data=='1'){-->
<!--							swal({-->
<!--								title:"登陆成功",-->
<!--								icon:'success'-->
<!--							}).then(function () {-->
<!--								location.href='./index.html';-->
<!--							});-->
<!--						}-->
<!--						else{-->
<!--							swal({-->
<!--								title: "登录失败",-->
<!--								icon: 'warning',-->
<!--								text:"对不起，您输入的账号密码有误！"-->
<!--							}).then(function () {-->
<!--								location.href='./login.html';-->
<!--							})-->
<!--						}-->
<!--					}-->
<!--				});-->

<!--			});-->
<!--			//给“记住我”按钮绑定记住账号事件-->
<!--			//   $('.checkbox').click(function () {-->
<!--			//     $.ajax({-->
<!--			//       type:'POST',-->
<!--			//       url:'./user.do',-->
<!--			//       data:{-->
<!--			//         username:$('#username').val(),-->
<!--			//         password:$('#inputPassword').val(),-->
<!--			//         action:'login'-->
<!--			//       },-->
<!--			//       dataType:'text'-->
<!--			//     });-->
<!--			//   })-->
<!--		})-->
<!--	</script>-->
    </body>
</html>